package com.yaorange.jk.service.impl;

import com.yaorange.jk.dao.BaseDao;
import com.yaorange.jk.entity.ShippingOrder;
import com.yaorange.jk.service.ShippingOrderService;
import com.yaorange.jk.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class ShippingOrderServiceImpl implements ShippingOrderService {
@Autowired
private BaseDao<ShippingOrder,String> shippingOrderDao;

@Override
public Pagination findPage(Pagination page) {
return shippingOrderDao.pageByHql("from ShippingOrder",page.getPageNo(),page.getPageSize(),null);
}

@Override
public List<ShippingOrder> findAll() {
    return shippingOrderDao.getListByHQL("from ShippingOrder");
    }

    @Override
    public void save(ShippingOrder model) {
    	model.setState(0d);
    shippingOrderDao.save(model);
    }

    @Override
    public void deleteById(String id) {
    shippingOrderDao.deleteById(ShippingOrder.class,id);
    }

    @Override
    public void update(ShippingOrder model) {
    shippingOrderDao.update(model);
    }

    @Override
    public ShippingOrder findById(String id) {
    return shippingOrderDao.get(ShippingOrder.class,id);
    }

	@Override
	public void shippingOrder(ShippingOrder sos) {
		sos.setState(1d);
		shippingOrderDao.update(sos);
	}

	@Override
	public Pagination findPage(Pagination page, double i) {
		return shippingOrderDao.pageByHql("from ShippingOrder s where s.state=?",page.getPageNo(),page.getPageSize(),i);
	}

	@Override
	public void cancel(ShippingOrder sos) {
		sos.setState(0d);
		shippingOrderDao.update(sos);
	}
    }
